<?php require_once LAYOUTPATH.'layout_header.php'; ?>

<h1><?php echo $page_title; ?></h1>

<div id="bricabox_tabs" class="admin">
	<ul>
		<li class="back"><a href="/">&lsaquo; Back to your BricaBox</a></li>
		<?php render_tabs($admin_tabs); ?>
	</ul>
</div>

<?php require_once FLASHPARTIAL; ?>

<table>
	<thead>
		<tr>
			<td>Name</td>
			<td>Fields</td>
			<td>Who can add these?</td>
			<td>Actions</td>
		</tr>
	</thead>
	<tbody>
		<?php if ($this->Bricabox_model->get_content_types($BBX['bricabox']->id) !== false): ?>
		<?php foreach ($this->Bricabox_model->get_content_types($BBX['bricabox']->id)->result() as $row): ?>
		<tr class="<?php echo alternator('even', 'odd'); ?>" id="entry_tpl_<?php echo $row->id; ?>">
			<td><a href="/entries/entry_type/<?php echo $row->name; ?>"><?php echo $row->name; ?></a></td>
			<td><?php echo field_list_to_string($row); ?></td>
			<td>
				<?php
				switch ($row->create_level)
				{
					case 3: echo 'Members, Moderators, and you'; break;
					case 4: echo 'Just Moderators and you'; break;
					case 5: echo 'Only you'; break;
				}
				?>
			</td>
			<td><a href="#" class="edit" onclick="return EntryTpl.startEdit(<?php echo $row->id; ?>);">Edit</a>
				<?php if ($this->Content_model->content_type_can_be_deleted($row->id, $row->bricabox_id)): ?>
				<a href="/admin/delete_entry_template/<?php echo $row->bricabox_id; ?>/<?php echo $row->id; ?>" class="delete" title="Delete" onclick="return confirm('Are you sure?');">
					<img src="/assets/images/icons/cross.png" alt="Delete" />
				</a>
				<?php endif; ?></td>
		</tr>
		<tr class="edit" id="edit_entry_tpl_<?php echo $row->id; ?>" style="display: none;">
			<form action="/admin/save_entry_template" method="post" onsubmit="return EntryTpl.saveTpl(<?php echo $row->id; ?>);">
				<input type="hidden" name="bricabox_id" value="<?php echo $row->bricabox_id; ?>" />
				<input type="hidden" name="current_name" value="<?php echo $row->name; ?>" />
				<input type="hidden" name="tpl[id]" value="<?php echo $row->id; ?>" />
				<td><input type="text" name="tpl[name]" id="template_name_<?php echo $row->id; ?>" value="<?php echo $row->name; ?>" /></td>
				<td><?php echo editable_field_list($row); ?></td>
				<td>
					<select name="tpl[create_level]">
						<?php
						foreach (array(
							3 => 'Members, Moderators, and you',
							4 => 'Just Moderators and you',
							5 => 'Only you'
						) as $level => $label)
						{
							$selected = ($level == $row->create_level) ? ' selected="selected"' : '';
							echo "\t<option value=\"{$level}\"{$selected}>{$label}</option>\n";
						}
						?>
					</select>
				</td>
				<td>
					<input type="submit" value="Save" />
					or <a href="#" onclick="return EntryTpl.endEdit(<?php echo $row->id; ?>);">cancel</a></td>
			</form>
		</tr>
		<?php endforeach; ?>
		<?php endif; ?>
		<tr class="bottom" id="entry_tpl_new">
			<td><a href="#" class="new" onclick="return EntryTpl.startEdit('new');">Create a new entry template</a></td>
			<td></td>
			<td></td>
			<td></td>
		</tr>
		<tr class="edit" id="edit_entry_tpl_new" style="display: none;">
			<form action="/admin/create_entry_template" method="post" onsubmit="return Bricabox.checkEntryTemplateName();">
				<input type="hidden" name="bricabox_id" value="<?php echo $BBX['bricabox']->id; ?>" />
				<td>
					<input type="text" id="template_name_new" name="tpl[name]" value="" /><br />
					Note: use the singluar, e.g. Place or Website
				</td>
				<td>
					<p class="tpl_info">In addition to a title, your entry can also have one or more of these optional fields:</p>
					<p><label for="use_upload"><input type="checkbox" id="use_upload" name="tpl[input_use_file_upload]" value="1" />
						File attachment</label>
						&rarr; Label: <input type="text" name="tpl[label_file_upload]" value="File attachment" /></p>
					<p><label for="use_url"><input type="checkbox" id="use_url" name="tpl[input_use_url]" value="1" />
						URL</label>
						&rarr; Label: <input type="text" name="tpl[label_url]" value="URL" /></p>
					<p><label for="use_address"><input type="checkbox" id="use_address" name="tpl[input_use_address]" value="1" />
						Address</label>
						&rarr; Label: <input type="text" name="tpl[label_address]" value="Address" /></p>
					<p><label for="use_subtitle"><input type="checkbox" id="use_subtitle" name="tpl[input_use_subtitle]" value="1" />
						A block of text</label>
						&rarr; Label: <input type="text" name="tpl[label_subtitle]" value="Block of text" /></p>
					<p><label for="use_datetime"><input type="checkbox" id="use_datetime" name="tpl[input_use_datetime]" value="1" />
						A date and time</label>
						&rarr; Label: <input type="text" name="tpl[label_datetime]" value="Date and time" /></p>
				</td>
				<td>
					<select name="tpl[create_level]">
						<?php
						foreach (array(
							3 => 'Members, Moderators, and you',
							4 => 'Just Moderators and you',
							5 => 'Only you'
						) as $level => $label)
						{
							echo "\t<option value=\"{$level}\">{$label}</option>\n";
						}
						?>
					</select>
				</td>
				<td>
					<input type="submit" value="Save" />
					or <a href="#" onclick="return EntryTpl.endEdit('new');">cancel</a></td>
			</form>
		</tr>
	</tbody>
</table>

<div class="big_info_box">
	<h4>What are Entry Templates?</h4>
	<p>Entry Templates allow you to define what types of content you are putting into your BricaBox. If you are adding content which requires location-based data, for example, it's important that you activate the Address field. If there are files associated with the information in your BricaBox, then the file field should also be activated. <strong>It is important to realize that you may have a number of different Entry Templates and that each Template can have its own Page Layout</strong>. You can also give your fields custom labels; be sure to include &quot;a&quot; or &quot;an&quot;, e.g. <em>a</em> file or <em>an</em> address.</p>
</div>

<?php require_once LAYOUTPATH.'layout_footer.php'; ?>